#ifndef DATAMANAGEMENT_H
#define DATAMANAGEMENT_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QStringList>

#include "globaldefine.h"

class DataManagement : public QObject
{
    Q_OBJECT
public:
    explicit DataManagement(QObject *parent = 0);
    ~DataManagement();

    void saveStockData();

private:
    bool initStockData();
    void initStockKLineData();
    void getStockKLineData(STOCKINFO &stockinfor);
    QString analyzeThisStock(STOCKINFO &stockinfor);
    void processStockData(QStringList &infoList, STOCKORGINFO &stockSrcinfo,
                          STOCKINFO &stockTarInfo);
    void obtainStocksOrgInfo(QString &stockStr);
    void dataProcess(STOCKORGINFO &stockSrcinfo, STOCKINFO &stockTarInfo);
    QColor getForegroundColor(double balance);
    QColor getBackgroundColor();

signals:
    void signalSendData(QHash<int, STOCKINFO> stocksInfoHash);

public slots:
    void slotReplyFinished(QNetworkReply* reply);
    void slotUpdateStockData();
    void slotAddSelectedStock(int code);
    void slotDeleteSelectedStock(int code);

private:
    QNetworkAccessManager *m_pNetAccMgr;

    STOCKORGINFO m_stockOrginfo;
    QStringList  m_stockCodeList;
    QString      m_tempStock;

    QList<KLINEDATA> m_KLineList;
};

#endif // DATAMANAGEMENT_H
